﻿namespace DimensionsHelper.Client.WinUi.ViewModels;

public partial class OptionalFileViewModel : ObservableObject
{
    [ObservableProperty]
    public partial string FileName { get; set; } = string.Empty;


    [ObservableProperty]
    public partial bool IsSelected
    {
        get;
        set;
    }


    public Action<OptionalFileViewModel>? RemoveHandler
    {
        get;
        set;
    }

    public event Action<OptionalFileViewModel>? Selected;

    public event Action<OptionalFileViewModel>? Unselected;


    partial void OnIsSelectedChanged(bool value)
    {
        if (value)
        {
            Selected?.Invoke(this);
        }
        else
        {
            Unselected?.Invoke(this);
        }
    }


    public bool CanRemove() => RemoveHandler != null;


    [RelayCommand(CanExecute = nameof(CanRemove))]
    private void Remove() => RemoveHandler?.Invoke(this);
}